<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Group extends La_Controller {
	function __construct() {
		parent::__construct();
		$this->load->model(array("Group_model", 'User_model','City_model','Category_model'));
		
		$this->data = array('page_title' => '行动网');
		$this->data['nav'] = 'group';
		$this->data['first_level_categories'] = $this->Category_model->find_son_category(1);
	}
	/**
	 * 一级目录列表
	 */
	public function index() {
		$this->page_title("合作组-行动网");
		$current_category_id = intval($this->uri->segment(2));
		if (empty($current_category_id)) {
			$current_category_id = 2;
		}
		$this->_lists($current_category_id);
	}
	
	
	/**
	 * 二级分类列表
	 */
	public function lists() {
		$this->page_title("合作组-行动网");
		$sub_category_id = intval($this->uri->segment(3));
		$current_category_id = $this->Category_model->find_father_category($sub_category_id);
		$this->_lists($current_category_id, $sub_category_id);
		
	}
	/**
	 * 列表
	 * @param int $current_category_id 一级分类
	 * @param int $sub_category_id 二级分类
	 */
	private function _lists($current_category_id, $sub_category_id = null) {
		$offset = intval($this->uri->segment(4));
		$this->data['current_category_id'] = $current_category_id;
		$this->data['provinces'] = $this->City_model->find_all_province();
		$this->data['tips_categories'] = $this->Category_model->find_son_category($current_category_id);
		$this->data['sub_category_id'] = ($sub_category_id ? $sub_category_id : (empty($this->data['tips_categories'][0]['id']) ? -1 : $this->data['tips_categories'][0]['id']));
		
		$this->data['group_count'] = $this->Group_model->get_count_by_category_id($this->data['sub_category_id']);
		$this->load->library('pager');
		$config['base_url'] = site_url("group/lists" . "/" . $this->data['sub_category_id'] ) . "/";
		$config['total_rows'] = $this->data['group_count'];
		$config['per_page'] = LA_PAGE_SIZE;
		$config['uri_segment'] = 4;
		$this->pager->initialize($config);
		
		$this->data['groups'] = $this->Group_model->find_by_category_id($this->data['sub_category_id'], $offset, $config['per_page']);
		
		$this->data['pager'] =  $this->pager->create_links();
		$this->load->view('group/index', $this->data);
	}
	
	/**
	 * 创建小组
	 */
	public function create() {
		$this->page_title("创建合作组-行动网");
		if (!$this->authorize->is_logged_in()) {
			la_redirect('user/login?ref=' . urlencode(site_url('group/create')), "请你先登录");
		}
		$user_id = $this->authorize->current_user();
		$group_count = $this->Group_model->get_count_by_condition($user_id);
		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
			$title = $this->input->post('title');
			$is_public = $this->input->post('is_public');
			$introduction = $this->input->post('introduction');
			$category_id = $this->input->post('category_id');
			$province_id = $this->input->post('province');
			$city_id = $this->input->post('city');
			$area_id = $this->input->post('area');
			$join_type = $this->input->post('join_type');
			$config['upload_path'] = './img/uploads/';
			$config['allowed_types'] = 'gif|jpg|png';
			$config['max_size']	= '4096';
			$this->load->library('upload', $config);
			$this->load->library('form_validation');
			$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
			$this->form_validation->set_rules('category_id', '群组类别', 'required');
			$this->form_validation->set_rules('title', '群组标题', 'required');
			if ($this->form_validation->run() == FALSE)
			{
				$this->load->view('group/create', $this->data);
				
			} else {
				if ($this->upload->do_upload() ) {
					$pic_data = $this->upload->data();
					$config['image_library'] = 'gd2';
					$config['source_image'] = ROOTPATH . '/img/uploads/' . $pic_data['file_name'];
					$config['create_thumb'] = TRUE;
					$config['maintain_ratio'] = false;
					$config['width'] = 160;
					$config['height'] = 80;
					$this->load->library('image_lib', $config);
					$this->image_lib->resize();
				} 
				
				$data = array( 'title' => $title, 'created_by' => $user_id, 'created' => date("Y-m-d H:i:s"),
									'introduction'=> $introduction, 'join_type' => $join_type,
									'is_public' => $is_public, 'category_id' => $category_id, 'province_id' => $province_id,
									'city_id' => $city_id, 'area_id' => $area_id, 'logo'=> (!empty($pic_data['raw_name']) ? ($pic_data['raw_name'] . "_thumb" . $pic_data['file_ext']) : ''));
				$group_id = $this->Group_model->add($data);
				$this->load->model("User_group_model");
				$this->User_group_model->add(array('user_id'=>$data['created_by'],'group_id'=>$group_id,
											'created'=>date("Y-m-d H:i:s"),'is_group_admin'=>1));
			}
			
			$this->load->view('group/create_success', array('group_id'=>$group_id, 'leave_count' => (3 - $group_count)));
		} else {
			if($group_count > 4) {
				$this->load->view('group/error', array('msg' => "您创建的群组已经超过上限"));
			} else {
				$this->data['provinces'] = $this->City_model->find_all_province();
				$this->data['first_level_categories'] = $this->Category_model->find_son_category(1);
				$this->load->view('group/create', $this->data);
			}
		}
	}
	
	/**
	 * 创建小组成功
	 */
	public function create_success() {
		$this->page_title("小组创建成功-行动网");
		$this->load->view('group/create_success');
	}
	
	/**
	 * 团队的查看页面
	 */
	public function view() {
		
		$offset= intval($this->uri->segment(3));
		$group_id = intval($this->input->get("group_id"));
		$group = $this->Group_model->find_by_id($group_id);
		$feedback = $this->input->get("feedback");
		if(empty($group)) {
			la_redirect("group/", "群组不存在");
		}
		if ($group['status'] != 1) {
			redirect("group/error");
		}
		$this->page_title( $group['title'] . "-行动网");
		$user_id = $this->authorize->current_user();
		$group_admins = $this->Group_model->find_users_by_group_id($group_id, 1);
		$group_users = $this->Group_model->find_users_by_group_id($group_id, 0, 15);
		$this->load->model("Thread_model");
		$this->data['thread_count'] = $this->Thread_model->get_count_by_group_id($group_id);
		$this->load->library('pager');
		$config['base_url'] = site_url("group/view") ;
		$config['total_rows'] = $this->data['thread_count'];
		$config['suffix'] = "?group_id=" . $group_id;
		$config['per_page'] = LA_PAGE_SIZE;
		$config['uri_segment'] = 3;
		$this->pager->initialize($config);
		$this->data['threads'] = $this->Thread_model->find_by_group_id($group_id, $offset, $config['per_page']);
		$this->data['pager'] =  $this->pager->create_links();
		
		$this->data['group_users'] = $group_users;
		$this->load->model("User_group_model");
		if ($this->User_group_model->is_member($user_id, $group_id)) {
			$this->data['is_member'] = 1;
		} else {
			$this->data['is_member'] = 0;
		}
		if ($this->User_group_model->is_group_admin($user_id, $group_id)) {
			$this->data['is_group_admin'] = 1;
		} else {
			$this->data['is_group_admin'] = 0;
		}
		if ($group['created_by'] == $user_id) {
			$this->data['is_founder'] = 1;
		} else {
			$this->data['is_founder'] = 0;
		}
		$this->data['group_admins'] = $group_admins;
		$this->data['group'] = $group;
		$this->data['feedback'] = $feedback;
		$this->load->view('group/view', $this->data);
	}
	
	/**
	 * 单条BBS的查看页面
	 */
	function forum_view() {
		$offset= intval($this->uri->segment(3));
		$thread_id = intval($this->input->get("thread_id"));
		$this->load->model(array('Thread_model', 'Post_model', 'User_group_model', 'Comment_model',));
		$thread = $this->Thread_model->find_by_id($thread_id);
		if (empty($thread)) {
			la_redirect("group", "帖子不存在");
		}
		$this->page_title($thread['title'] . "-行动网");
		$this->Thread_model->update_view_count($thread_id);
		$group = $this->Group_model->find_by_id($thread['group_id']);
		if ($group['status'] != 1) {
			la_redirect("group/", "群组未审核");
		}
		$this->data['post_count'] = $this->Post_model->get_count_by_thread_id($thread_id);
		$this->load->library('pager');
		$config['base_url'] = site_url("group/forum_view") ;
		$config['total_rows'] = $this->data['post_count'];
		$config['suffix'] = "?thread_id=" . $thread_id;
		$config['per_page'] = LA_PAGE_SIZE;
		$config['uri_segment'] = 3;
		$this->pager->initialize($config);
		$posts = $this->Post_model->find_by_thread_id($thread_id, $offset, $config['per_page']);
		
		if (!empty($posts)) {
			$user_string = '-1';
			foreach($posts as &$post) {
				$user_string .= "," . $post['created_by'];
				$post['score'] = 0;
				$post['vertification'] = '';
			}
			unset($post);
			$scores = $this->Comment_model->find_average_score($user_string, 'user');
			for($i = 0, $n = count($scores); $i < $n; $i++) {
				foreach($posts as &$post) {
					if ($post['created_by'] == $scores[$i]['target_id']) {
						$post['score'] = $scores[$i]['score'];
					}
				}
				unset($post);
			}
			
			$verts = $this->User_model->find_vertification_info($user_string);
			for($i = 0, $n = count($verts); $i < $n; $i++) {
				foreach($posts as &$post) {
					if ($post['created_by'] == $verts[$i]['created_by']) {
						if($verts[$i]['total']) {
							$post['vertification'] = "是";
						} else {
							$post['vertification'] = "否";
						}
					}
				}
				unset($post);
			}
		}
		$this->data['pager'] =  $this->pager->create_links();
		$this->data['posts'] = $posts;
		
		
		$user_id = $this->authorize->current_user();
		$this->data['is_group_admin'] = $this->User_group_model->is_group_admin($user_id, $thread['group_id']);
		$this->data['group'] = $group;
		$this->data['thread'] = $thread;
		$this->load->view('group/forum_view', $this->data);
	}
	
	/**
	 * BBS的创建
	 */
	function newthread() {
		$this->page_title("发布新帖-行动网");
		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
			$data['title'] = $this->input->post('title');
			$data['content'] = $this->input->post('content');
			$data['group_id'] = $this->input->post('group_id');
			$data['created_by'] = $this->authorize->current_user();
			$data['created'] = $data['modified'] = date("Y-m-d H:i:s");
			$data['last_poster'] = $data['created_by'];
			$this->load->model('Thread_model');
			$thread_id = $this->Thread_model->add($data);
			redirect("group/forum_view/?thread_id=" . $thread_id);
		} else {
			$group_id = $this->input->get("group_id");
			if (empty($group_id)) {
				la_redirect("", "请选择发贴的组");
			}
			$group = $this->Group_model->find_by_id($group_id);
			if ($group['status'] != 1) {
				la_redirect("group/", "群组未审核或者已经删除");
			}
			$user_id = $this->authorize->current_user();
			if (!$user_id) {
				la_redirect('user/login?ref=' . urlencode(site_url('group/newthread?group_id=' . $group_id)), "请你先登录");
			}	
			
			$this->load->model(array("User_group_model", "Banned_model"));
			if ($this->User_model->is_user_forbidden_talk($user_id)/* || !$this->Banned_model->has_post_priviledge($user_id)*/)	{
				la_redirect('/group/view?group_id=' . $group_id, "您被禁言了");
			}
			if (!$this->User_group_model->is_member($user_id, $group_id))	{
				la_redirect('/group/view?group_id=' . $group_id, "请您先加入此群组");
			}
			$this->data['group'] = $group;
			$this->load->view('group/forum_edit', $this->data);
		}
	}
	/**
	 * 回复后跳转
	 */
	function goto_post() {
		
		$thread_id = $this->input->get("thread_id");
		$post_id = $this->input->get("post_id");
		if (empty($thread_id) || empty($post_id)) {
			redirect("group/");
		}
		$this->load->model('Post_model');
		$page_num = $this->Post_model->get_page_num($post_id , $thread_id);
		redirect("group/forum_view/" . $page_num . "?thread_id=" . $thread_id . "#post-" . $post_id);
	}
	/**
	 * 回帖
	 */

	
	function reply_post() {
		$this->page_title("回复-行动网");
		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
			$data['title'] = '';
			$data['thread_id'] = $this->input->post('thread_id');
			$data['is_thread'] = 0;
			$data['content'] = $this->input->post('content');
			$data['group_id'] = $this->input->post('group_id');
			$data['created_by'] = $this->authorize->current_user();
			$data['created'] = date("Y-m-d H:i:s");
			
			$this->load->model('Post_model');
			$post_id = $this->Post_model->add($data);
			redirect("group/goto_post/?thread_id=" . $data['thread_id'] . "&post_id=" . $post_id);
		} else {
			$this->load->model(array("User_group_model"));
			$thread_id = $this->input->get("thread_id");
			if (empty($thread_id)) {
				la_redirect("", "请选择回复的主题");
			}
			$this->load->model("Thread_model");
			$thread = $this->Thread_model->find_by_id($thread_id);
			$user_id = $this->authorize->current_user();
			if (!$user_id) {
				la_redirect('user/login?ref=' . urlencode(site_url('group/reply?thread_id=' . $thread_id)), "请你先登录");
			}
			$this->load->model( "Banned_model");
			if ($this->User_model->is_user_forbidden_talk($user_id))	{
				la_redirect("group/forum_view/?thread_id=" . $thread_id, "您被禁言了");
			}
			if (!$this->User_group_model->is_member($user_id, $thread['group_id']))	{
				la_redirect('/group/view?group_id=' . $thread['group_id'], "请您先加入此群组");
			}
			
			$this->data['thread'] = $thread;
			$this->load->view('group/post_edit', $this->data);
		}
	}
	/**
	 * 主题的管理操作
	 */
	function thread_manager() {
		$thread_id = $this->input->get("thread_id");
		if (empty($thread_id)) {
			la_redirect("", "请选择回复的主题");
		}
		$user_id = $this->authorize->current_user();
		$this->load->model(array("User_group_model", "Thread_model"));
		$thread = $this->Thread_model->find_by_id($thread_id);
		$is_group_admin = $this->User_group_model->is_group_admin($user_id, $thread['group_id']);
		if (!$is_group_admin) {
			la_redirect('group/forum_view?thread_id=' . $thread_id, "无权限进行此操作");
		}
		$act = $this->input->get("act");
		
		$act_array = array('delete','top', 'untop', 'down', 'undown', 'highlight', 'unhighlight', 'digest', 'undigest','closed', 'unclosed');
		if(!in_array($act, $act_array)) {
			die(0);
		}
		$map_array = array(
						"top" => array('key' => 'is_top', 'value' => 1),
						"untop" => array('key' => 'is_top', 'value' => 0),
						"down" => array('key' => 'is_down', 'value' => 1),
						"undown" => array('key' => 'is_down', 'value' => 0),
						"highlight" => array('key' => 'highlight', 'value' => 1),
						"unhighlight" => array('key' => 'highlight', 'value' => 0),
						"digest" => array('key' => 'digest', 'value' => 1),
						"undigest" => array('key' => 'digest', 'value' => 0),
						"closed" => array('key' => 'closed', 'value' => 1),
						"unclosed" => array('key' => 'closed', 'value' => 0),
						);
		if ($act == 'delete') {
			$this->Thread_model->delete($thread_id);
			la_redirect('group/view?group_id=' . $thread['group_id'], "删除成功");
		} else {
			$this->Thread_model->set_field($map_array[$act]['key'], $map_array[$act]['value'], ' id=' . $thread_id);
			la_redirect('group/forum_view?thread_id=' . $thread_id, "修改成功");
		}
	}
	/**
	 * 加入群组
	 */
	function join() {
		$group_id = intval($this->input->get("group_id"));
		$group = $this->Group_model->find_by_id($group_id);
		
		if(empty($group)) {
			la_redirect("group/", "群组不存在");
		}
		if ($group['status'] != 1) {
			la_redirect("group/", "群组未审核");
		}
		$user_id = $this->authorize->current_user();
		if (!$user_id) {
			la_redirect('user/login?ref=' . urlencode(site_url('group/join?group_id=' . $group_id)), "请你先登录");
		}	
		
		$this->load->model("User_group_model");
		if ($this->User_group_model->is_joined($user_id, $group_id)) {
			la_redirect("group/view?feedback=joined&group_id=" . $group_id, "你加入过该小组");
		}
		if ($group['join_type'] == 0) {
			$this->User_group_model->add(array('user_id' => $user_id, 'status' => 0 ,'group_id' => $group_id, 'created' => date("Y-m-d H:i:s")));
			la_redirect("group/view?feedback=join_wait_verify&group_id=" . $group_id, "已经申请加入此小组，请等待管理员审核");
		} else {
			$this->User_group_model->add(array('user_id' => $user_id, 'group_id' => $group_id, 'created' => date("Y-m-d H:i:s")));
			redirect("group/view?group_id=" . $group_id);
		}
	}
	/**
	 * 退出群组
	 */
	function quit() {
		$group_id = intval($this->input->get("group_id"));
		$group = $this->Group_model->find_by_id($group_id);
		
		if(empty($group)) {
			la_redirect("group/", "群组不存在");
		}
		
		$user_id = $this->authorize->current_user();
		if (!$user_id) {
			la_redirect('user/login?ref=' . urlencode(site_url('group/quit?group_id=' . $group_id)), "请你先登录");
		}	
		if ($user_id == $group['created_by']) {
			la_redirect("group/view?group_id=" . $group_id, "创始人不能退出");
		}
		$this->load->model("User_group_model");
		$this->User_group_model->delete($user_id, $group_id);
		redirect("group/view?group_id=" . $group_id);
	}
	/**
	 * 群组管理
	 */
//	function admin() {
//		$this->page_title("群组管理-行动网");
//		$this->load->model(array("User_group_model"));
//		$group_id = intval($this->input->get("group_id"));
//		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
//			$group_id = intval($this->input->post("id"));
//		}
//		$action = $this->input->get("action");
//		if(empty($action)) $action = "settting";
//		$group = $this->Group_model->find_by_id($group_id);
//		
//		if(empty($group)) {
//			la_redirect("group/", "群组不存在");
//		}
//		
//		$user_id = $this->authorize->current_user();
//		if (!$user_id) {
//			la_redirect('user/login?ref=' . urlencode(site_url('group/join?group_id=' . $group_id)), "请你先登录");
//		}
//		
//		if (!$this->User_group_model->is_group_admin($user_id, $group_id)) {
//			redirect("group/view?group_id=" . $group_id);
//		}
//		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
//			$introduction = $this->input->post('introduction');
//			$logo = $this->input->post('logo');
//			$config['upload_path'] = './img/uploads/';
//			$config['allowed_types'] = 'gif|jpg|png';
//			$config['max_size']	= '4096';
//			$this->load->library('upload', $config);
//			if ($this->upload->do_upload() ) {
//				$pic_data = $this->upload->data();
//				$config['image_library'] = 'gd2';
//				$config['source_image'] = ROOTPATH . '/img/uploads/' . $pic_data['file_name'];
//				$config['create_thumb'] = TRUE;
//				$config['maintain_ratio'] = false;
//				$config['width'] = 160;
//				$config['height'] = 80;
//				$this->load->library('image_lib', $config);
//				$this->image_lib->resize();
//			}
//			$id = $this->input->post('id');
//			$data = array( 'id' => $id,
//							'introduction'=> $introduction,
//							'logo'=> !empty($pic_data) ? ($pic_data['raw_name'] . "_thumb" . $pic_data['file_ext']) : $logo);
//			$group_id = $this->Group_model->add($data);
//			redirect("group/admin?group_id=" . $group_id);
//			exit(0);
//		} else {
//			$this->data['group_id'] = $group_id;
//			$this->data['group'] = $group;
//			if ($action == 'member') {
//				$offset= intval($this->uri->segment(3));
//				$this->load->library('pager');
//				$config['base_url'] = site_url("group/admin_member") ;
//				$config['total_rows'] = $this->User_group_model->get_user_count($group_id);
//				$config['suffix'] = "?action=member&group_id=" . $group_id;
//				$config['per_page'] = LA_PAGE_SIZE;
//				$config['uri_segment'] = 3;
//				$this->pager->initialize($config);
//				$this->data['members'] = $this->User_group_model->find_users($group_id, $offset, $config['per_page']);
//				
//				$this->data['pager'] =  $this->pager->create_links();
//				$this->load->view('group/admin_member', $this->data);
//			} else if ($action == 'member_verify') {
//				$offset= intval($this->uri->segment(3));
//				$this->load->library('pager');
//				$config['base_url'] = site_url("group/admin") ;
//				$config['total_rows'] = $this->User_group_model->get_user_count($group_id, 0);
//				$config['suffix'] = "?action=member_verify&group_id=" . $group_id;
//				$config['per_page'] = LA_PAGE_SIZE;
//				$config['uri_segment'] = 3;
//				$this->pager->initialize($config);
//				$this->data['members'] = $this->User_group_model->find_users($group_id, $offset, $config['per_page'], 0);
//				
//				$this->data['pager'] =  $this->pager->create_links();
//				$this->load->view('group/admin_verify', $this->data);
//			}
//			else {
//				$this->load->view('group/admin', $this->data);
//			}
//		}
//	}
	
	function admin() {
		$this->page_title("群组管理-行动网");
		$this->load->model(array("User_group_model"));
		$group_id = intval($this->input->get("group_id"));
		if ($_SERVER['REQUEST_METHOD']  == 'POST') {
			$group_id = intval($this->input->post("id"));
		}
		$action = $this->input->get("action");
		if(empty($action)) $action = "settting";
		$group = $this->Group_model->find_by_id($group_id);
		
		if(empty($group)) {
			la_redirect("group/", "群组不存在");
		}
		if ($group['status'] != 1) {
			redirect("group/error");
		}
		$user_id = $this->authorize->current_user();
		if (!$user_id) {
			la_redirect('user/login?ref=' . urlencode(site_url('group/join?group_id=' . $group_id)), "请你先登录");
		}
		
		if (!$this->User_group_model->is_group_admin($user_id, $group_id)) {
			redirect("group/view?group_id=" . $group_id);
		}
		
		$this->data['group_id'] = $group_id;
		$this->data['group'] = $group;
		$this->data['v_members'] = $this->User_group_model->find_users($group_id, 0, null, 0);
		$this->data['admins'] = $this->User_group_model->find_group_admins($group_id);
		$this->load->view('group/admin', $this->data);
	}
	function admin_op() {
		$this->load->model(array("User_group_model", "User_model"));
		$group_id = intval($this->input->post("group_id"));
		$action = $this->input->post("action");
		$group = $this->Group_model->find_by_id($group_id);
		
		if(empty($group)) {
			la_redirect("group/", "群组不存在");
		}
		
		$user_id = $this->authorize->current_user();
		if (!$user_id) {
			la_redirect('user/login?ref=' . urlencode(site_url('group/admin_op?group_id=' . $group_id)), "请你先登录");
		}
		
		if (!$this->User_group_model->is_group_admin($user_id, $group_id)) {
			redirect("group/view?group_id=" . $group_id);
		}
		$id = intval($this->input->get("id"));
		if($action == 'delete') {
			$nick = $this->input->post("nick_off");
			$user = $this->User_model->find_user_by_nick($nick);
			
			if (empty($user)) {
				la_redirect("/group/admin?group_id=" . $group_id, "用户不存在，请重新设置");
			}
			$this->User_group_model->delete($user['id'], $group_id);
		} else if($action == 'toadmin') {
			$count = $this->User_group_model->get_admin_count($group_id);
			if ($count >= 4) {
				la_redirect("/group/admin?group_id=" . $group_id, "群组最多有四个管理员，请取消其他管理员后再设置新管理员");
			}
			$nick = $this->input->post("nick");
			$user = $this->User_model->find_user_by_nick($nick);
			
			if (empty($user)) {
				la_redirect("/group/admin?group_id=" . $group_id, "用户不存在，请重新设置");
			}
			
			if (!$this->User_group_model->is_member($user['id'], $group_id)) {
				la_redirect("/group/admin?group_id=" . $group_id, "用户不是改小组成员");
			}
			$this->User_group_model->set_as_admin($user['id'], $group_id);
		} else if($action == 'removeadmin') {
			$ids = $this->input->post("admins");
			foreach($ids as $id) {
				if ($id == $user_id) {
					continue;
				}
				$this->User_group_model->set_as_admin($id, $group_id, 0);
			}
		} else if($action == 'allow') {
			$ids = $this->input->post("v_members");
			foreach($ids as $id) {
				$this->User_group_model->allow($id, $group_id, 0);
				$user_group = $this->User_group_model->find_by_id($id);
				$post_data['msg_to_id'] = $user_group['user_id'];
				$post_data['is_system'] = 1;
				$post_data['subject'] = "你被批准加入小组";
				$post_data['content'] = "尊敬的用户： <br/>
		          <br/> 你已经被批准加入群组<a href='/group/view?group_id=" . $group_id. "'>" . $group['title'] . "</a>";
				$post_data['msg_from_id'] = 0;
				$post_data['msg_from'] = '行动网';
				$post_data['created'] = date("Y-m-d H:i:s");
				$post_data['related_id'] = 0;
				$this->load->model('Message_model');
				$this->Message_model->add($post_data);
			}
		}
		la_redirect("/group/admin?group_id=" . $group_id, "操作成功");
	}
	
	function error() {
		$this->load->view('group/error', array('msg' => "群组审核中，请耐心等待..."));
	}
}